Skip to content

Time-step limits: directional diffusive CFL numbers, interface-only capillary limit, compact run_time.inf - #2406

Open
wilfonba wants to merge 2 commits into
MFlowCode:masterfrom
wilfonba:timeStepLimits
Open

wilfonba wants to merge 2 commits into
MFlowCode:masterfrom
wilfonba:timeStepLimits

Conversation

@wilfonba

@wilfonba wilfonba commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Contribution Policy

All contributions are expected to demonstrate:

  • A clear understanding of the codebase
  • Alignment with product direction
  • Thoughtful reasoning behind changes
  • Evidence of real-world usage or hands-on experience with the problem

If these expectations are not met, we would prefer to implement the changes ourselves rather than spend time reviewing low-effort submissions.

Summary

s_compute_dt_from_cfl and s_compute_stability_from_dt (src/simulation/m_sim_helpers.fpp) bounded the explicit viscous and conduction steps by D dt / min(dx)^2 <= cfl_target, with D = max(1/Re)/rho. An explicit diffusion of diffusivity D is RK-stable for D dt sum_d(1/dx_d^2) <= 2.51/4 (RK3; 2/4 for RK1 and RK2): the directions add, and the normal stresses diffuse with (4 mu/3 + mu_b)/rho, the largest coefficient of the viscous stress. The old number therefore understated the stability number by num_dims times 4/3 (more with bulk viscosity), and a viscous-limited cfl_adap_dt run at an ordinary cfl_target could be unstable. This PR changes the three diffusive and capillary limits; it is a CFD-result change for cfl_adap_dt/cfl_const_dt runs that one of them limits, and it changes the VCFL, TCFL and CCFL values that run_time.inf reports for every run.

  • VCFL is now dt (4/(3 Re_1) + 1/Re_2)/rho * sum_d(1/dx_d^2) (f_visc_diffusivity, f_inv_dx2_sum). On a uniform grid with shear viscosity only it is 4/3, 8/3 and 4 times the old number in 1D, 2D and 3D. The chem_params%transport_dt branch is unchanged: its Re already sums the directions.
  • TCFL is now dt k/(rho c_v) * sum_d(1/dx_d^2), with the diffusivity from the new s_compute_cell_diffusivity, so it is 1, 2 and 3 times the old number.
  • CCFL uses Brackbill's capillary density, the mean of the phase densities, and applies only in cells where every phase's volume fraction exceeds capillary_alpha_min = 1e-3 (f_capillary_rho). The mixture density let the light phase's bulk cells, which carry no capillary force, set a far smaller step than the interface does.
  • run_time.inf prints its columns two blanks apart and its CFL numbers as ES10.3 instead of F10.6, which showed a small number such as 2.6e-3 to three digits. The closing summary uses the same format. The write blocks are about 20 lines shorter.

cfl_target in docs/documentation/case.md now states what it bounds.

Verification

examples/2D_viscous (two fluids, Re(1) = Re(2) = 1e-4 so mu_b = mu, 100 x 100 uniform, WENO, RK3), switched to cfl_adap_dt = T and run to t = 4e-7, serial CPU, NVHPC 26.3, wingtip. It is viscous-limited throughout. "Before" is master at 7982f2d. With bulk viscosity in 2D the new VCFL is (4/3 + 1) * 2 = 14/3 times the old one.

cfl_target build first dt new-definition VCFL of that dt steps outcome
0.2 master 2.000e-9 0.93 200 completes
0.2 this PR 4.286e-10 0.20 933 completes
0.5 master 5.000e-9 2.33 29 NaN at step 30
0.5 this PR 1.071e-9 0.50 373 completes

Master at cfl_target = 0.5 is at 3.7 times the RK3 limit and fails in 30 steps. The two runs of this PR agree in the final conservative state to 3.4e-6 of its largest value; master's completed run at 0.2 differs from them by 6.1e-5, against a total change from the initial condition of 9.1e-4, so it is past the limit (0.93 against 0.63) without having blown up yet.

Tests. Fixed-dt runs cannot change: the limits enter only s_compute_dt and the reported numbers. Of the 1034 suite cases, the 28 that set cfl_adap_dt or cfl_const_dt (17 generated cases and 11 examples) all pass on this branch against master's goldens, CPU, NVHPC 26.3; none of them is limited by a criterion this PR changes, so no golden is regenerated. The same definitions have also run the full suite in #2098's CI (1015 passed on the GNU lane).

Not verified: a conduction-limited or capillary-limited case before and after (the TCFL and CCFL changes are checked by reading, and by the tests above passing); 3D; the cylindrical branch with the filtered azimuthal spacing, which f_inv_dx2_sum handles as the old code did but which no run here exercised; GPU builds (the kernels gain one private scalar and one device routine, s_compute_cell_diffusivity); non-Newtonian cases, whose viscous-limited examples are on the suite's skip list; whether any user's post-processing parses the old run_time.inf columns.

Sample run_time.inf

From the cfl_target = 0.2 runs of the table above (examples/2D_viscous, adaptive step), table header, first rows and closing summary. Both hold VCFL at the target; the step differs because the number does.

Before (master):

             Time-step                     dt                   Time               ICFL Max               VCFL Max                       Rc Min
                     0              2.000E-09              0.000E+00               0.010385               0.200000                 1.149870E-03
                     1              2.000E-09              2.000E-09               0.010385               0.200000                 1.149870E-03
                     2              2.000E-09              4.000E-09               0.010385               0.200000                 1.149870E-03
                     3              2.000E-09              6.000E-09               0.010385               0.200000                 1.149870E-03
...
ICFL Max:  0.010385
VCFL Max:  0.200000
Rc Min:     1.149870E-03

After (this PR):

Time-step          dt        Time    ICFL Max    VCFL Max      Rc Min
        0   4.286E-10   0.000E+00   2.225E-03   2.000E-01   1.150E-03
        1   4.286E-10   4.286E-10   2.225E-03   2.000E-01   1.150E-03
        2   4.286E-10   8.571E-10   2.225E-03   2.000E-01   1.150E-03
        3   4.286E-10   1.286E-09   2.225E-03   2.000E-01   1.150E-03
...
ICFL Max:  2.225E-03
VCFL Max:  2.000E-01
Rc Min:  1.150E-03

Type of change

  • Bug fix

Testing

./mfc.sh precheck; the 28 CFL-step tests and the 2D_viscous comparison above on NVHPC 26.3 CPU.

Related: split out of #2098, which carries the same changes.

This PR was made with Claude Code (AI).

🤖 Generated with Claude Code

@wilfonba
wilfonba requested a review from a team as a code owner November 22, 2026 17:25
@wilfonba
wilfonba requested review from sbryngelson and removed request for a team November 22, 2026 17:25
@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: ab44ed3

Files changed:

  • 5
  • docs/documentation/case.md
  • src/common/m_constants.fpp
  • src/simulation/m_data_output.fpp
  • src/simulation/m_sim_helpers.fpp
  • src/simulation/m_time_steppers.fpp

Findings:
No issues found. Checked m_sim_helpers.fpp, m_time_steppers.fpp, m_data_output.fpp and m_constants.fpp against their callers, declarations, GPU private lists and the Re/Dth conventions.

@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.71429% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.21%. Comparing base (398733e) to head (c6d286e).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
src/simulation/m_sim_helpers.fpp 56.25% 20 Missing and 8 partials ⚠️
src/simulation/m_data_output.fpp 72.22% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2406      +/-   ##
==========================================
+ Coverage   66.14%   66.21%   +0.06%     
==========================================
  Files         112      112              
  Lines       31093    31100       +7     
  Branches     4749     4752       +3     
==========================================
+ Hits        20567    20593      +26     
+ Misses       6675     6664      -11     
+ Partials     3851     3843       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

danieljvickers
danieljvickers previously approved these changes Nov 22, 2026
@github-actions

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/simulation/m_sim_helpers.fpp 296 +26
src/simulation/m_data_output.fpp 1912 -13
src/simulation/m_time_steppers.fpp 1022 +2
src/common/m_constants.fpp 106 +1
Directory Lines Diff
common 12522 +1
simulation 41880 +15
total 61956 +16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants